package shwp.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import shwp.modelo.BusinessDelegate;

@WebServlet("/Backup")
public class Backup extends ServletBase {
	private static final long serialVersionUID = 1L;
       
    public Backup() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		borrarVariablesSesion(request,"Backup");
		String msj;
		String accion = request.getParameter("accion");
		String destino = "backup.jsp";
		
		switch ( accion ) {
			case "backup":
				String prefijo = request.getParameter("prefijo");
				if ( prefijo == "" )
					prefijo = "sin_prefijo";
				msj = BusinessDelegate.getInstancia().generarBackup(prefijo);
				if ( msj == "OK"){
					mensajeExito = "Backup generado exitosamente.";
				}else{
					 mensajeError = "Ocurri&oacute; un problema inesperado al intentar generar el backup. Por favor p&oacute;ngase en contacto con el administrador.";
				}
				break;
			}				
		this.redirect( request, response, destino );
	}
	
}
